package com.ruoyi.project.business.dailyschedulerule.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.dailyschedulerule.entity.DailyscheduleRule;
import com.ruoyi.project.business.dailyschedulerule.request.AddDailyscheduleRuleRequest;
import com.ruoyi.project.business.dailyschedulerule.request.ListDailyscheduleRuleRequest;
import com.ruoyi.project.business.dailyschedulerule.response.DailyscheduleRuleResponse;
import com.ruoyi.project.business.dailyschedulerule.service.IDailyscheduleRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日排班规则Controller
 * 
 * @author ${author}
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/business/dailyschedulerule")
public class DailyscheduleRuleController extends BaseController {
    @Autowired
    private IDailyscheduleRuleService dailyscheduleRuleService;

    /**
     * 查询日排班规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListDailyscheduleRuleRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<DailyscheduleRuleResponse> list = dailyscheduleRuleService.selectDailyscheduleRuleList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出日排班规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:export')")
    @Log(title = "日排班规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListDailyscheduleRuleRequest request) {
        Long tenantId = getTenantId();
        List<DailyscheduleRuleResponse> list = dailyscheduleRuleService.selectDailyscheduleRuleList(request, tenantId);
        ExcelUtil<DailyscheduleRuleResponse> util = new ExcelUtil<>(DailyscheduleRuleResponse.class);
        return util.exportExcel(list, "dailyschedulerule");
    }

    /**
     * 获取日排班规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dailyscheduleRuleService.selectDailyscheduleRuleById(id));
    }

    /**
     * 新增日排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:add')")
    @Log(title = "日排班规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddDailyscheduleRuleRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(dailyscheduleRuleService.insertDailyscheduleRule(request, operatorId, tenantId));
    }

    /**
     * 修改日排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:edit')")
    @Log(title = "日排班规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyscheduleRule dailyscheduleRule) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(dailyscheduleRuleService.updateDailyscheduleRule(dailyscheduleRule, operatorId, tenantId));
    }

    /**
     * 删除日排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:dailyschedulerule:remove')")
    @Log(title = "日排班规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(dailyscheduleRuleService.deleteDailyscheduleRuleByIds(ids, operatorId, tenantId));
    }
}
